#pragma once

#include <config.h>

#include <gl/glew.h>
#include <renderer/renderer.h>
#include <oglRenderer/oglTexture.h>
#include <oglRenderer/oglDisplayList.h>
BEGIN_NAMESPACE_OXGE



class Color;
class Material;

class oglColorBuffer;
class oglDepthBuffer;
class oglStencilBuffer;
class oglAccumBuffer;
class oglModelViewMatrixStack;
class oglProjectionMatrixStack;
class oglTextureUnit;

#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")



class oglContext : public oxgeClass<oglContext>
{
public:

	virtual void makeCurrent()=0;

	
	
	virtual void shareDislayList(oglContext* pOtherContex)
	{
		m_pTexRes = pOtherContex->m_pTexRes;
		m_pDisplistRes = pOtherContex->m_pDisplistRes;		
	}
	
protected:
	oglTextureResource::RefPtr m_pTexRes;
	oglDisplayListResource::RefPtr m_pDisplistRes;

};




//opengl state machine pipeline renderer ,the rendering context
class oglRenderer : public Renderer
{
public:	
	void Initialize() ;
	
	//resources
	std::vector<oglTextureUnit::RefPtr> m_vTexUnits;

	virtual void Render(SceneNode* pNode,const ViewPort& viewport);

	oglContext::RefPtr m_pMainContex;
	std::vector<oglContext::RefPtr> m_vAuxContex;

protected:
	void DrawSceneObject(SceneObject* pObject);

	void ApplyMaterial(const Material& pmat, GLenum side); //side == GL_FORNT, GL_BACK, GL_FRONT_AND_BACK
	void ApplyColor(const Color& color);
	
protected:
	void TraverseNodeTree(SceneNode* pNode);
};






END_NAMESPACE_OXGE